package com.realtyManage.springboot.Controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.realtyManage.springboot.Config.WxProgramPayConfig;
import com.realtyManage.springboot.Model.Do.*;
import com.realtyManage.springboot.Model.Vo.BaseEntity;
import com.realtyManage.springboot.Model.Vo.CustomReEntity;
import com.realtyManage.springboot.Model.Vo.RegEntity;
import com.realtyManage.springboot.Model.Vo.UserTaskEntity;
import com.realtyManage.springboot.Service.*;
import com.realtyManage.springboot.Service.impl.DictionariesServiceImpl;
import com.realtyManage.springboot.Service.impl.HouseFansServiceImpl;
import com.realtyManage.springboot.Service.impl.UserTaskServiceImpl;
import com.realtyManage.springboot.Utils.BuildTreeUtil;
import com.realtyManage.springboot.Utils.RedisService;
import com.realtyManage.springboot.Utils.SysExecRsUtil;
import com.realtyManage.springboot.wxpay.PayUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * VikiController
 * 购房百科
 * @Author 杭州素色网络科技有限公司
 * @Date 2019/11/27
 **/

@Controller
@RequestMapping("/")
public class VikiController {
    @Autowired
    private VikiService vikiService;

    /**
     * 获取购房百科（百科池）
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryVikiListPool",method = RequestMethod.GET)
    public String queryVikiListPool(HttpServletRequest request){
        return JSON.toJSONString(vikiService.queryVikiListPool());
    }

    /**
     * 获取购房百科（启用数据）
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryVikiList",method = RequestMethod.GET)
    public String queryVikiList(HttpServletRequest request){
        String title = request.getParameter("title");
        return JSON.toJSONString(vikiService.queryVikiList(title));
    }

    /**
     * 购房百科详情
     * @param request
     * @return
     * @throws ParseException
     */
    @ResponseBody
    @RequestMapping(value = "/queryVikiById",method = RequestMethod.GET)
    private String queryVikiById(HttpServletRequest request) throws ParseException {
        String id = request.getParameter("id");
        return  JSON.toJSONString(vikiService.queryVikiById(Integer.valueOf(id)));
    }

    /**
     * 新增购房百科
     * @param viki
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/saveViki",method = RequestMethod.POST)
    private String saveViki(Viki viki, HttpServletRequest request) {
        viki.setIsShow(0);
        viki.setTime(new Date());
        Integer code = -1;
        if (vikiService.saveViki(viki) > 0){
            code = 1;
        }
        RegEntity re = new RegEntity();
        re.setInfoCode(code);
        re.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(re);
    }


    /**
     * 是否启用购房百科/修改购房百科
     * @param viki
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/isEnableViki",method = RequestMethod.POST)
    private String isEnableViki(Viki viki,HttpServletRequest request) {
        String isEnableViki = request.getParameter("isEnableViki");
        Integer code = -1;
        if (vikiService.updateViki(viki) > 0){
            code = 1;
        }
        RegEntity re = new RegEntity();
        re.setInfoCode(code);
        re.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(re);
    }



}
